home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / !SFcolours / c / SFCIconbar < prev    next >
Encoding:
Text File  |  2003-10-24  |  3.7 KB  |  117 lines

  1. /*
  2.  *  SFcolours - Star Fighter 3000 colours editor
  3.  *  Iconbar icon
  4.  *  Copyright (C) 2001  Chris Bazley
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public Licence as published by
  8.  *  the Free Software Foundation; either version 2 of the Licence, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public Licence for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public Licence
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /* ANSI library files */
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. /* RISC OS library files */
  27. #include "wimp.h"
  28. #include "toolbox.h"
  29. #include "event.h"
  30. #include "wimplib.h"
  31. #include "iconbar.h"
  32.  
  33. /* My library files */
  34. #include "err.h"
  35. #include "msgtrans.h"
  36. #include "Macros.h"
  37. #include "Loader.h"
  38. #include "SFformats.h" /* get Fednet filetype */
  39. #include "ViewsMenu.h"
  40.  
  41. /* Local headers */
  42. #include "EditColmap.h"
  43. #include "Utils.h"
  44. #include "SFCCreateFile.h"
  45. #include "SFCIconbar.h"
  46.  
  47. static ObjectId Iconbar_id;
  48.  
  49. /* ----------------------------------------------------------------------- */
  50. /*                       Function prototypes                               */
  51.  
  52. static LoaderFinishedHandler _Iconbar_openfile;
  53. static ToolboxEventHandler _Iconbar_click;
  54.  
  55. /* ----------------------------------------------------------------------- */
  56. /*                         Public functions                                */
  57.  
  58. void Iconbar_initialise(ObjectId id)
  59. {
  60.   Iconbar_id = id;
  61.  
  62.   /* Listen for clicks */
  63.   EF(event_register_toolbox_handler(id, Iconbar_Clicked, _Iconbar_click, NULL));
  64.  
  65.   /* Register listeners for files dropped on iconbar icon */
  66.   EF(loader_register_listener(0, FILETYPE_FEDNET, id, NULL, load_compressed, _Iconbar_openfile, NULL));
  67. }
  68.  
  69. /* ----------------------------------------------------------------------- */
  70. /*                         Private functions                               */
  71.  
  72. static int _Iconbar_click(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
  73. {      
  74.   if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Select)) {
  75.     /* create new file */
  76.     RE(toolbox_show_object(Toolbox_ShowObject_AsMenu, CreateFile_sharedid, Toolbox_ShowObject_Centre, NULL, id_block->self_id, id_block->self_component))
  77.     return 1; /* claim event */
  78.   }
  79.  
  80.   if(FLAG_SET(((IconbarClickedEvent *)event)->hdr.flags, Iconbar_Clicked_Adjust)) {
  81.     /* bring all open windows to front */
  82.     RE(ViewsMenu_showall())
  83.     return 1; /* claim event */
  84.   }
  85.  
  86.   return 0; /* event not handled */
  87. }
  88.  
  89. /* ----------------------------------------------------------------------- */
  90.  
  91. static void _Iconbar_openfile(char *title, bool data_saved, flex_ptr buffer,int filetype, void *handle)
  92. {
  93.   /* Open a new editing window */
  94.   ObjectId editing_win;
  95.  
  96.   if(flex_size(buffer) != sizeof(SF_ColourMap) && flex_size(buffer) != sizeof(SF_HillCols)) {
  97.     flex_free(buffer);
  98.     M_RET("NoSuchFileType") /* Code or someting */
  99.   }
  100.  
  101.   /* Check for existing windows */
  102.   if(!data_saved || (editing_win = ViewsMenu_findview(title)) == NULL_ObjectId) {
  103.  
  104.     /* Create editing window */
  105.     editing_win = EditColmap_create(buffer, (flex_size(buffer) == sizeof(SF_HillCols)), title, data_saved);
  106.     if(editing_win == NULL) {
  107.       flex_free(buffer);
  108.       return;
  109.     }
  110.   }
  111.   else
  112.     flex_free(buffer); /* Already have an open editing window */
  113.  
  114.   /* Open editing window */
  115.   RE(show_win_at_ptr(0, editing_win, Iconbar_id, NULL_ComponentId))
  116. }
  117.